Skip to content

ACP Implementation of PermissionsExt for Windows #152995

Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:windows_permissions_ext
Open

ACP Implementation of PermissionsExt for Windows #152995
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:windows_permissions_ext

Conversation

@asder8215
Copy link
Copy Markdown
Contributor

@asder8215 asder8215 commented Feb 23, 2026

View all comments

This PR implements the PermissionsExt for Windows ACP and adds file attribute methods in FilePermissions struct (to be decided whether we use them or not). See this tracking issue for further detail and links.

I also added some comments in the code for clarifications about the ACP (e.g. whether we should have a set_file_attributes() + from_file_attributes() method to mirror what unix's PermissionsExt is doing).

Also, some relevant links on this:

Note: Apologies for the multiple forced push. I haven't set up my Windows VM up yet to compile and check the code, so I've been using the CI to help me with that.

r? @ChrisDenton

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 23, 2026

ChrisDenton is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 00739a8 to 2daf248 Compare February 23, 2026 01:04
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 2daf248 to 29689a6 Compare February 23, 2026 05:47
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 29689a6 to b752775 Compare February 23, 2026 06:54
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from b752775 to 23a096f Compare February 23, 2026 07:15
Comment thread library/std/src/os/windows/fs.rs Outdated
/// let mut permissions = Permissions::set_file_attributes(my_file_attr);
/// assert_eq!(permissions.mode(), my_file_attr);
/// ```
pub trait PermissionsExt {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permissions struct doesn't have a Sealed trait bound (the Unix version of PermissionsExt doesn't use a Sealed trait bound either), so I'm unsure if this should be done here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any new structs like this should be sealed. The reason the Unix version of PermissionExt doesn't is an historical artefact and one we'd love to fix. Otherwise it makes adding any functions a breaking change (this can be worked around by adding PermissionExt2 but we'd rather avoid that if possible).

@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 23a096f to 3ed985e Compare February 23, 2026 07:36
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 3ed985e to 696ce60 Compare February 23, 2026 07:58
Comment thread library/std/src/os/windows/fs.rs Outdated
Comment thread library/std/src/os/windows/fs.rs Outdated
///
/// // readonly and hidden file attributes that we
/// // want to add to existing file
/// let my_file_attr = 0x1 | 0x2;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a public example, this should use constants instead of magic values, even if that means defining the constants right about this line.

Comment thread library/std/src/os/windows/fs.rs Outdated
/// );
/// Ok(())
/// }
/// ```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this whole example seems much more like a test than an example. I think it's better for users if examples are kept short and to the point.

Comment thread library/std/src/os/windows/fs.rs Outdated
Comment thread library/std/src/sys/fs/windows.rs Outdated
Comment on lines +1166 to +1167
// According to SetFileAttributes, any other values
// passed to this should override FILE_ATTRIBUTE_NORMAL
Copy link
Copy Markdown
Member

@ChrisDenton ChrisDenton Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows itself will override FILE_ATTRIBUTE_NORMAL if another attribute is present so I'm not sure it's necessary for us to do it. But if we do do it then I'd rather use a bitmask rather than repeating if self.normal() each time. Or maybe an internal-only helper function.

@asder8215
Copy link
Copy Markdown
Contributor Author

asder8215 commented Mar 3, 2026

I'll get to updating this PR later today!

To note, the doctest/example was inspired from the Unix version. I mirrored writing it in the way Unix doc for PermissionsExt did. I do agree with you that I should use const value with specific names than just directly using magic values and clarify the docs a bit more on file attributes. I'm open to bitmasking the normal file attribute out through using an XOR operation and then ORing the result with respective file attributes (and if this actually ends up being unnecessary, I can remove it later down the line).

I'll try and see if I can apply the Sealed trait bound on PermissionsExt, but I also recall receiving a compiler error when I tried that earlier saying that Permissions doesn't implement Sealed trait so I can't implement PermissionsExt on Permissions (I may be misremembering though, will have to check later today).

Thanks for taking a look at this PR @ChrisDenton!

@ChrisDenton
Copy link
Copy Markdown
Member

I'll try and see if I can apply the Sealed trait bound on PermissionsExt, but I also recall receiving a compiler error when I tried that earlier saying that Permissions doesn't implement Sealed trait so I can't implement PermissionsExt on Permissions (I may be misremembering though, will have to check later today).

You should just be able implement Sealed for PermissionExt.

To note, the doctest/example was inspired from the Unix version. I mirrored writing it in the way Unix doc for PermissionsExt did.

Yeah, after looking at the Unix example I do find that a bit verbose. In either case, considering the example is no_run I do think there should be a test somewhere that actually runs and tests this works.

@asder8215
Copy link
Copy Markdown
Contributor Author

asder8215 commented Mar 4, 2026

If there are no compilation errors, then yea I've added your feedback. Let me know if the doc comments for PermissionsExt is okay! I took off the larger no_run example and kept the smaller one in.

On a side note, I've been looking at FilePermissions/Permissions methods and I kind of wished the set_* methods returned itself so that it would be possible to just chain the methods. If the other Windows file attributes have the okay to be implemented on PermissionsExt, do you think it would be fine to just return Self instead of bool for its setter methods?

@rust-log-analyzer

This comment has been minimized.

@asder8215
Copy link
Copy Markdown
Contributor Author

Yeah, after looking at the Unix example I do find that a bit verbose. In either case, considering the example is no_run I do think there should be a test somewhere that actually runs and tests this works.

I'm down to update the Unix example in a separate PR to reduce verbosity. As for testing the functions here, where would be the appropriate place to do that for this PR?

Moreover, does CI here run Windows tests? I've been wondering that a bit because in my Reverse Ancestor PR, I have Windows tests there for paths with Prefix components, but I didn't see anything in CI that mentions that it ran my Windows test (and passes).

@asder8215
Copy link
Copy Markdown
Contributor Author

Also, yea the Sealed trait bound gives me a compilation error for some reason:
image

  error[E0277]: the trait bound `Permissions: Sealed` is not satisfied
     --> library/std/src/os/windows/fs.rs:399:25
      |
  399 | impl PermissionsExt for Permissions {
      |                         ^^^^^^^^^^^ unsatisfied trait bound
      |
  help: the trait `Sealed` is not implemented for `Permissions`
     --> library/std/src/fs.rs:294:1
      |
  294 | pub struct Permissions(fs_imp::FilePermissions);
      | ^^^^^^^^^^^^^^^^^^^^^^
      = help: the following other types implement trait `Sealed`:
                Child
                OsStr
                OsString
                Simd<f32, N>
                Simd<f64, N>
                StderrLock<'_>
                StdinLock<'_>
                StdoutLock<'_>
              and 12 others
  note: required by a bound in `PermissionsExt`
     --> library/std/src/os/windows/fs.rs:383:27
      |
  383 | pub trait PermissionsExt: Sealed {
      |                           ^^^^^^ required by this bound in `PermissionsExt`

@asder8215 asder8215 requested a review from ChrisDenton March 4, 2026 04:55
@ChrisDenton
Copy link
Copy Markdown
Member

You'll need to impl Sealed for Permissions. Take a look at FileTypeExt, it should be doing something similar.

@asder8215
Copy link
Copy Markdown
Contributor Author

asder8215 commented Mar 4, 2026

You'll need to impl Sealed for Permissions. Take a look at FileTypeExt, it should be doing something similar.

Oh okay, I could do that. I was worried that I may not be allowed to do that if it's a breaking change.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from b53af07 to 09f0506 Compare March 4, 2026 22:24
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 18, 2026

📌 Commit 782a214 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 19, 2026
… r=Mark-Simulacrum

ACP Implementation of PermissionsExt for Windows

This PR implements the `PermissionsExt` for Windows ACP and adds file attribute methods in `FilePermissions` struct (to be decided whether we use them or not). See this [tracking issue](rust-lang#152956 (comment)) for further detail and links.

I also added some comments in the code for clarifications about the ACP (e.g. whether we should have a `set_file_attributes()` + `from_file_attributes()` method to mirror what unix's `PermissionsExt` is doing).

Also, some relevant links on this:
* [File Attribute Constants](https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants)
* [`attrib` command](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/attrib)
* [SetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesa)
* [GetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesa)
* [Window's File Attributes Column Values](https://superuser.com/questions/44812/windows-explorers-file-attribute-column-values)
* [What is the 'M' attribute in Windows file system for?](https://superuser.com/questions/1621649/what-is-the-m-attribute-in-windows-file-system-for)

Note: Apologies for the multiple forced push. I haven't set up my Windows VM up yet to compile and check the code, so I've been using the CI to help me with that.

r? @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
Rollup of 8 pull requests

Successful merges:

 - #155370 (Add regression test for dead code elimination with drop + panic)
 - #154823 (Replace the spdx-rs dependency with a minimal in-tree SPDX tag-value parser)
 - #155352 (triagebot.toml: Sync `assign.owners` with `autolabel."T-compiler"`)
 - #155431 (Add temporary scope to assert_matches)
 - #152995 (ACP Implementation of PermissionsExt for Windows )
 - #153873 (deprecate `std::char` constants and functions)
 - #154654 (Move `std::io::ErrorKind` to `core::io`)
 - #154865 (libtest: use binary search for --exact test filtering)
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 19, 2026
… r=Mark-Simulacrum

ACP Implementation of PermissionsExt for Windows

This PR implements the `PermissionsExt` for Windows ACP and adds file attribute methods in `FilePermissions` struct (to be decided whether we use them or not). See this [tracking issue](rust-lang#152956 (comment)) for further detail and links.

I also added some comments in the code for clarifications about the ACP (e.g. whether we should have a `set_file_attributes()` + `from_file_attributes()` method to mirror what unix's `PermissionsExt` is doing).

Also, some relevant links on this:
* [File Attribute Constants](https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants)
* [`attrib` command](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/attrib)
* [SetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesa)
* [GetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesa)
* [Window's File Attributes Column Values](https://superuser.com/questions/44812/windows-explorers-file-attribute-column-values)
* [What is the 'M' attribute in Windows file system for?](https://superuser.com/questions/1621649/what-is-the-m-attribute-in-windows-file-system-for)

Note: Apologies for the multiple forced push. I haven't set up my Windows VM up yet to compile and check the code, so I've been using the CI to help me with that.

r? @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
Rollup of 9 pull requests

Successful merges:

 - #155370 (Add regression test for dead code elimination with drop + panic)
 - #154823 (Replace the spdx-rs dependency with a minimal in-tree SPDX tag-value parser)
 - #154972 (Implement `core::arch::return_address` and tests)
 - #155294 (Add test for coalescing of diagnostic attribute duplicates)
 - #155352 (triagebot.toml: Sync `assign.owners` with `autolabel."T-compiler"`)
 - #155431 (Add temporary scope to assert_matches)
 - #152995 (ACP Implementation of PermissionsExt for Windows )
 - #153873 (deprecate `std::char` constants and functions)
 - #154865 (libtest: use binary search for --exact test filtering)
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 19, 2026
… r=Mark-Simulacrum

ACP Implementation of PermissionsExt for Windows

This PR implements the `PermissionsExt` for Windows ACP and adds file attribute methods in `FilePermissions` struct (to be decided whether we use them or not). See this [tracking issue](rust-lang#152956 (comment)) for further detail and links.

I also added some comments in the code for clarifications about the ACP (e.g. whether we should have a `set_file_attributes()` + `from_file_attributes()` method to mirror what unix's `PermissionsExt` is doing).

Also, some relevant links on this:
* [File Attribute Constants](https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants)
* [`attrib` command](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/attrib)
* [SetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesa)
* [GetFileAttributesA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesa)
* [Window's File Attributes Column Values](https://superuser.com/questions/44812/windows-explorers-file-attribute-column-values)
* [What is the 'M' attribute in Windows file system for?](https://superuser.com/questions/1621649/what-is-the-m-attribute-in-windows-file-system-for)

Note: Apologies for the multiple forced push. I haven't set up my Windows VM up yet to compile and check the code, so I've been using the CI to help me with that.

r? @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
Rollup of 10 pull requests

Successful merges:

 - #155370 (Add regression test for dead code elimination with drop + panic)
 - #154823 (Replace the spdx-rs dependency with a minimal in-tree SPDX tag-value parser)
 - #155294 (Add test for coalescing of diagnostic attribute duplicates)
 - #155352 (triagebot.toml: Sync `assign.owners` with `autolabel."T-compiler"`)
 - #155431 (Add temporary scope to assert_matches)
 - #152995 (ACP Implementation of PermissionsExt for Windows )
 - #153873 (deprecate `std::char` constants and functions)
 - #154865 (libtest: use binary search for --exact test filtering)
 - #154979 (add #[must_use] macros for floats)
 - #155504 (Remove `AttributeLintKind` variants - part 2)
@Zalathar
Copy link
Copy Markdown
Member

Failed in rollup: #155511 (comment)

@bors r-
@bors try jobs=aarch64-msvc-1

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 19, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 19, 2026

This pull request was unapproved.

This PR was contained in a rollup (#155511), which was unapproved.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
ACP Implementation of PermissionsExt for Windows 


try-job: aarch64-msvc-1
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 19, 2026

💔 Test for 5618143 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@asder8215
Copy link
Copy Markdown
Contributor Author

I think I need to put the feature flag inside the doctest no_run portion. Forgot to do that.

…tilities to observe, set, and create a Permissions struct with certain file attributes
@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 782a214 to c567332 Compare April 19, 2026 18:47
@asder8215
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2026
@Zalathar
Copy link
Copy Markdown
Member

@bors try jobs=aarch64-msvc-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
ACP Implementation of PermissionsExt for Windows 


try-job: aarch64-msvc-1
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 20, 2026

☀️ Try build successful (CI)
Build commit: d95c421 (d95c421c4d8d169205dcdfda7756e63fe76894d9, parent: e22c616e4e87914135c1db261a03e0437255335e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants